
 var query={
    currentPage:1,	
  	totalPage:1,
  	pageSize:10,
  };
 var chooseId=0;
$(function(){
  var endId=[];
  var insertid;
  var deleteid;
  initTaskDis();
  requestRefer(query);//已提交数据
  //跳转到详情界面
  $(document).on("click",".detail",function(){
	  var id= $(this).attr("data-id");
		var menuId=$("#menu-container").attr("menu-id");
		window.location.href = '../information/subDetailInfo.jsp?menuId='+menuId+'&detailId=' + id;
  })


 

  
  $(document).on("click",".input-task-finsh-context",function(){
	  var account=$(this).attr("data-account");
	  var taskId=$(this).attr("data-taskId");
	  var id=$(this).attr("data-id");
	  $("#modal-input-task-finsh-context").modal("show");	 
	  $("#modal-infoAccount").attr("placeholder","信息编号:"+id);
	  $("#input-task-finsh-btn").attr("data-id",id);
	  $("#input-task-finsh-btn").attr("data-taskId",taskId);
	 // $("#modal-input-context").text();
  })
 
  $("#input-task-finsh-btn").click(function(){
	  var id=$(this).attr("data-id");
	  var taskId=$(this).attr("data-taskId");
	  var context=$("#modal-input-context").val();
	  YuXi.util.get("TaskFinshFilter/inputTaskFinshContext.do",{inforId:id,taskId:taskId,context:context},function(data){
		  $("#modal-input-task-finsh-context").modal("hide");	 
		  myTool.alert({
			 title:"提示",
			 context:data.msg
		 });
	  },function(){
		  myTool.alert({
				 title:"提示",
				 context:"未知错误"
			 });
	  });
	  
  });
  
  
  $(document).on("click",".insert-task",function(){
	  insertid="infoId="+$(this).attr("data-id");
	  $("#Mymodal").modal('show');
  });
  //提交模态框按钮
  $("#btnSure").click(function(){	
	  requestSure(insertid);//调用提交方法;
  })

  //分页，首页
  $("#headPage").click(function(){
	query.currentPage=1;
  	$("#totalPage").html(query.currentPage+"/"+query.totalPage);
  	requestRefer(query);
  })
  

  //分页，尾页
  $("#endPage").click(function(){
  	$("#totalPage").html(query.totalPage+"/"+query.totalPage);
  	query.currentPage=query.totalPage;
  	requestRefer(query);
  })
  //分页，上一页
  $("#prevPage").click(function(){
  	if(query.currentPage<=1)
  	{
  		query.currentPage=1;
  	}
  	else
  	{
  		query.currentPage=query.currentPage-1;
  		$("#totalPage").html(query.currentPage+"/"+query.totalPage);  
  		requestRefer(query);
  	}

 })
 
  //分页，下一页
   $("#nextPage").click(function(){
  	
  	if(query.currentPage>=query.totalPage)
  	{
  		query.currentPage=query.currentPage;
  	}
  	else
  	{
  		query.currentPage=query.currentPage+1;
  		$("#totalPage").html(query.currentPage+"/"+query.totalPage);
  		requestRefer(query);
  	}
  	
  })
  
})

//提交按钮
function requestSure(id)
{
	  alert(id);
	  var url="TaskDispatchFilter/taskSubToTaskFinish.do";//提交的地址
	  YuXi.util.get(url,id,function(data){
		  if(data.status)
		  {
			  $("#successmodel").modal('show');
		  }
		  else
		  {
			 
			  $("#badmodal").modal('show');
		  }
	  },function(){
		  $("#badmodal").modal('show');
	  })
}

//向后台请求的信息数据
function requestRefer(data){
	var url="getUserInputTaskContext.do";
	////console.log(JSON.stringify(data));
	YuXi.util.get(url,data,function(data){	 
		object=data.list;
		query.totalPage=data.totalPage;
		query.page=data.currentPage;
		$("#totalPage").html(query.page+"/"+query.totalPage);
		$("#table1body").html("");
		for(var i=0;i<object.length;i++)
		{
			if( object[i].informationProfile.length>15)
				object[i].informationProfile= object[i].informationProfile.substring(0,15)+"...";
			var time=YuXi.getTime.get(object[i].zeRenTime*1);
			var remark=object[i].remark;
			if(remark==undefined||remark==null){
				remark="";
			}
			var html="<tr ><td>"+ object[i].informationAccount+"</td><td >"+object[i].informationProfile+"</td>"+
			
			"<td >"+object[i].informationClassificationNames+"</td>+" +
			"<td >"+object[i].informationSourceNames+"</td>"+
			"<td >"+object[i].safetyPortNames+"</td>"+
			"<td >"+object[i].personDispatchName+"</td>"+
			"<td >"+time+"</td>"+
			"<td >"+remark+"</td>"+"<td>" + object[i].userName + "</td>"+
			"<td><a href='javascript:void(0);' data-id="+object[i].id +" class='detail'>详情</a>&nbsp;&nbsp;</td></tr>";
			
			$("#table1body").append(html);
		}
		
	
	},function(){});
  

}
$("#firstSearch").click(function(){
	firstSearch();
});
//简介，分级，渠道，状态，时间（今天,一周...）查找
function firstSearch()
{
	
	var information={};
	query.key=$("#profile").val();//简介
/*	information.state=$(".state option:selected").val()//当前状态
*/	query.informationSource=$(".reSearchSource option:selected").val()//来源渠道
	query.informationType=$(".reSearchpes option:selected").val()//分级
	query.salfPort=$(".task-port option:selected").val()
	var value=$(".valTime option:selected").val();	
	var array=[];
	var starTime=$("#starTime").val();
	var endTime=$("#endTime").val();
	array=YuXi.timestamp.get(starTime,endTime,null);
	query.startTimestamp=array[0];
	query.endTimestamp=array[1];
	query.currentPage=1;	
	requestRefer(query);
	
	
}

function initTaskDis(){
	 YuXi.util.get("getAllInformationClassification.do",null,function(data){
		 if(data.status){
			 var obj=data.object;
			 for(var i=0;i<obj.length;i++){
				 $(".reSearchpes").append("<option value='"+obj[i].id+"' >"+obj[i].name+"</option>");
			 }
			 
		 }
	 });
	 
	 YuXi.util.get("getAllInfomationSource.do",null,function(data){
		 if(data.status){
			 var obj=data.object;
			 for(var i=0;i<obj.length;i++){
				 $(".reSearchSource").append("<option value='"+obj[i].id+"' >"+obj[i].name+"</option>");
			 }
			 
		 }
	 });
	 
	 YuXi.util.get("getSafetyPortList.do",null,function(data){
		 if(data.status){
			 var obj=data.object;
			 for(var i=0;i<obj.length;i++){
				 $(".task-port").append("<option value='"+obj[i].id+"' >"+obj[i].name+"</option>");
			 }
			 
		 }
	 });
	
}
